//
//  WCWeiboFunctionController.m
//  WeboCon
//
//  Created by black sun on 12-3-4.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "WCWeiboFunctionController.h"


@implementation WCWeiboFunctionController
@synthesize tableView;
@synthesize delegate;
@synthesize uid;
@synthesize userService;
@synthesize user;

-(id)initWithUid:(NSNumber *)_uid{
    self = [super initWithNibName:@"WCWeiboFunctionController" bundle:nil];
    if (self) {
        self.uid = _uid;
        self.userService = [WCUserService serviceWithDelegate:self];
        [userService getUserByUid:self.uid];
        self.user = [User entityWithId:self.uid];
    }
    return self;
}

- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView{
    return 6;
}

- (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row{
    HTTPImageView *imageView = [[HTTPImageView alloc] init];
    switch (row) {
        case 0:
            imageView.url = self.user.profile_image_url;
            break;
        case 1:
            imageView.image = [NSImage imageNamed:@"timeline-blue.png"] ;
            break;
        case 2:
            imageView.image = [NSImage imageNamed:@"mentions-blue.png"] ;
            break;
        case 3:
            imageView.image = [NSImage imageNamed:@"star_small.jpeg"] ;
            break;
        case 4:
            imageView.image = [NSImage imageNamed:@"messages-blue.png"];
            break;
        case 5:
            imageView.image = [NSImage imageNamed:@"favorite-blue.png"] ;
            break;
        default:
            break;
    }
    return imageView;
}
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row{
    return row==0?50.0:40.0;
}

- (void)tableViewSelectionDidChange:(NSNotification *)aNotification{
    NSUInteger selectedRow = self.tableView.selectedRow;
    if (selectedRow==0 && [delegate respondsToSelector:@selector(wantToChangeUser:)]) {
        [delegate performSelector:@selector(wantToChangeUser:) withObject:uid];
        [self.tableView deselectRow:0];
    }
}

-(void)requestDidFinishedWithResult:(id)result andUserInfo:(NSDictionary *)userInfo{
    NSString *action = [userInfo objectForKey:kRequestTypeKey];
    if ([action isEqualToString:GetUserByUid]) {
        self.user = result;
    }
}

-(void)requestDidFailureWithError:(NSError *)error andUserInfo:(NSDictionary *)userInfo{
    
}

@end
